package com.power.sifa.approve.model.doc;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.power.sifa.approve.model.enumeration.Tp_procmaterial;
import com.power.sifa.approve.service.BusinessApproveService;
import lombok.Data;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * @ClassName HearAuditDelayDoc
 * @Author xiongzw
 * @Date 2023/11/24 15:48
 * @Description 延期审理通知书
 * @Version: 1.0
 **/
@Data
public class HearAuditDelayDoc  extends AbstractDoc {

    /**
     * 申请人
     */
    private String apl_admreview_applyname;
    /**
     * 正文
     */
    private String content;

    /**
     * 抄送
     */
    private String copyto;

    /**
     * 默认延期天数
     */
    private Integer daySize = 10;


    public HearAuditDelayDoc() {
        super();
        this.setDocType(Tp_procmaterial.HEAR_DELAY);
    }

    public HearAuditDelayDoc(String applyid) {
        super(applyid);
        this.setDocType(Tp_procmaterial.HEAR_DELAY);
    }

    public HearAuditDelayDoc(String applyid, String apl_admreview_applyname, String content, String copyto) {
        super(applyid);
        this.setDocType(Tp_procmaterial.HEAR_DELAY);
        this.apl_admreview_applyname = apl_admreview_applyname;
        this.content = content;
        this.copyto = copyto;
    }

    private final static String TEMPLATE = "    {pronoun}对{apl_admreview_targetname}[{behavior}]不服，于{apl_main_subtime}提出的行政复议申请，本府依法已予受理。经审理，本府认为，本案情况复杂，不能在规定期限内作出行政复议决定。根据《中华人民共和国行政复议法》第三十一条第一款的规定";

    private final static String DATE_TEMPLATE = "，行政复议决定延期{daySize}日作出。";

    @Override
    public AbstractDoc generateTemplate(String applyid) {
        HearAuditDelayDoc template = new HearAuditDelayDoc(applyid);
        // 案号
        template.setApl_admre_audit_code(this.getApl_admre_audit_code());
        template.setApl_admreview_applyname(ObjectUtil.isNotNull(this.getAdmreObj()) ? this.getAdmreObj().getApplyname() : "");
        String content = TEMPLATE.replace("{apl_admreview_targetname}", ObjectUtil.isNotNull(this.getAdmreObj()) ?
                this.getAdmreObj().getTargetname() : "" );
        content = content.replace("{behavior}", this.transBehavior());
        content = content.replace("{pronoun}", this.transPronoun());
        content = content.replace("{apl_main_subtime}", this.transSubtime());
//        content = content + DATE_TEMPLATE.replace("{extensionday}", this.getExtensionday().toString());
        template.setContent(content);
        template.setCopyto("（其他当事人）");
        return template;
    }

    public void transDate(Map<String, Object> docfield) {

        if (ObjectUtil.isNotNull(docfield)) {
            if (docfield.containsKey("content") && docfield.containsKey("daySize")) {
                String content = docfield.get("content").toString();
                Integer extensionday = Integer.parseInt(docfield.get("daySize").toString());
                content = content + DATE_TEMPLATE.replace("{daySize}", extensionday.toString());
                docfield.put("content", content);
                // 查询出工作日
                SimpleDateFormat format = new SimpleDateFormat("yyyy年M月d日");
                BusinessApproveService businessApproveService = SpringUtil.getBean(BusinessApproveService.class);
                Date extensionDate = businessApproveService.getTargetDay(new Date(), extensionday);
                docfield.put("extensionday", format.format(extensionDate));
            }
        }
    }

}
